UNPKG

946 BJavaScriptView Raw
1// outputs webpack stats to console if there are no errors or warnings
2
3import colors from 'colors/safe'
4
5function error(error)
6{
7 console.error(colors.red(error))
8}
9
10function warning(warning)
11{
12 console.log(colors.yellow(warning))
13}
14
15let first_run = true
16let was_faulty = false
17
18export default function notify_stats(stats, json, verbose)
19{
20 // if there were any errors
21 if (json.errors && json.errors.length > 0)
22 {
23 was_faulty = true
24 return json.errors.forEach(error)
25 }
26
27 // if there were any warnings
28 if (json.warnings && json.warnings.length > 0)
29 {
30 json.warnings.forEach(warning)
31 }
32
33 // if it's ok
34
35 if (!verbose && !first_run && was_faulty)
36 {
37 // green colour
38 console.log(colors.green('~ Webpack build status: OK ~'))
39
40 was_faulty = false
41 }
42
43 if (verbose || first_run)
44 {
45 console.log(stats.toString
46 ({
47 chunks: false,
48 colors: true
49 }))
50
51 first_run = false
52 }
53}